<?php
// +----------------------------------------------------------------------
// | DCloud [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.yunku.cloud All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <DCloud@126.com>
// +----------------------------------------------------------------------
namespace app\portal\model;

use think\Model;

class PortalLostModel extends Model
{
    protected $autoWriteTimestamp = true;

    // 关联文章
    public function article() {
        return $this->belongsTo('PortalPostModel', 'post_id', 'id');
    }

    public function save($data = [], $where = [], $sequence = null)
    {
        if(isset($data['status'])) {
            if($data['status'] == 0) {
                // 取消
                $this->article->save(['post_status' => 1]);
            } elseif ($data['status'] == 4) {
                // 审核不通过
                $this->article->save(['post_status' => 1]);
            } elseif ($data['status'] == 2) {
                // 审核通过
                $this->article->save(['post_status' => 3]);
            }
        }
        return parent::save($data, $where, $sequence); // TODO: Change the autogenerated stub
    }

}